﻿/*
 * ServiceContext
 * 
 * Author: snowdreamist
 * Date: 2011/12/14
 * 
 */

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;

namespace BitTorrentSharp.KRPC
{
    public class ServiceContext : IDisposable
    {
        #region thread static
        [ThreadStatic]
        private static ServiceContext _current;
        /// <summary>
        /// Current ServiceContext
        /// </summary>
        public static ServiceContext Current
        {
            get
            {
                return _current;
            }
            private set
            {
                _current = value;
            }
        }

        #endregion

        public ServiceContext()
        {
            if (ServiceContext.Current != null)
                throw new InvalidOperationException("ServiceContext.Current is not null");
            ServiceContext.Current = this;
        }

        #region properties
        /// <summary>
        /// EndPoint
        /// </summary>
        public EndPoint EndPoint { get; set; }

        #endregion

        /// <summary>
        /// Dispose
        /// </summary>
        public void Dispose()
        {
            ServiceContext.Current = null;
        }
    }
}
